package cn.tedu.medicalpath.inspection.service.impl;

import cn.tedu.medicalpath.base.constant.InspectionStatus;
import cn.tedu.medicalpath.inspection.mapper.InspectionMapper;
import cn.tedu.medicalpath.inspection.pojo.dto.InspectionSaveParam;
import cn.tedu.medicalpath.inspection.pojo.entity.Inspection;
import cn.tedu.medicalpath.inspection.pojo.vo.SubInspectionVO;
import cn.tedu.medicalpath.inspection.service.InspectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class InspectionServiceImpl implements InspectionService {

    @Autowired
    InspectionMapper inspectionMapper;

    @Override
    public void updateById(InspectionSaveParam inspectionSaveParam) {
        log.debug("开始处理【更新检查单】的请求，参数：{}", inspectionSaveParam);
        Inspection inspection = new Inspection();
        BeanUtils.copyProperties(inspectionSaveParam, inspection);
        inspection.setUpdateTime(new Date());
        inspectionMapper.updateById(inspection);
    }

    @Override
    public SubInspectionVO queryById(Long id) {
        log.debug("开始处理【查询检查单】的请求，参数：{}", id);
        return inspectionMapper.queryById(id);
    }

    @Override
    public long insertNull(Long patientId, Long doctorId) {
        log.debug("开始处理【插入空检查单】的请求，参数：{},{}", patientId, doctorId);
        Inspection inspection = new Inspection();
        inspection.setPatientId(patientId);
        inspection.setDoctorId(doctorId);
        inspection.setCreateTime(new Date());
        //设置状态为“05”
        inspection.setStatus(InspectionStatus.UNSAVED);
        inspectionMapper.insertNull(inspection);
        return inspection.getId();
    }
}
